package net.solvetheriddle.wwclient;

import net.solvetheriddle.wwclient.activity.MainActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class WWAlarmReciever extends BroadcastReceiver {

    public static final String CALLED_BY_ALARM = "CALLED_BY_ALARM";
    public static final String ACTION_WWALARM = "net.solvetheriddle.wwclient.ACTION_WWALARM";
    private Intent startIntent;
    
    @Override
    public void onReceive(Context context, Intent intent) {
        NotificationManager nManager =(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification alarmTriggered = new Notification(R.drawable.icon, "WorkWatch - zadejte odpracovanou činnost", System.currentTimeMillis());
        
        startIntent = new Intent(context, MainActivity.class);
        startIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startIntent.putExtra(CALLED_BY_ALARM, true);
        
        alarmTriggered.setLatestEventInfo(context, "WorkWatch Client", "Zapište prosím odpracovanou činnost", PendingIntent.getActivity(context, 0, startIntent, PendingIntent.FLAG_CANCEL_CURRENT));
        alarmTriggered.defaults |= Notification.DEFAULT_ALL;
        alarmTriggered.flags |= Notification.FLAG_AUTO_CANCEL;
        
        nManager.notify(0, alarmTriggered);
    }

}
